﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Database.Linq.Translators;
using CoreEx.Database.Query.Expressions;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Linq.Implementation.Translators
{
    [Implements(typeof(IExpressionTranslator_generic<ConstantExpression>))]
    public class ConstantExpressionTranslatorGeneric : ExpressionTranslatorGenericBase<ConstantExpression>
    {
        public ConstantExpressionTranslatorGeneric(TranslateResult translateResult) : base(translateResult)
        {
        }


        public override DbExpression Translate(ConstantExpression expression)
        {
            if (expression.IsQueryable())
                return CreateQuery(((IQueryable)expression.Value).ElementType);
            return ExpressionFactory.Constant(expression.Value);
        }
    }
}
